<template>
	手机号码:<input v-model="tel" /><br>
	验证码:<input v-model="wnum" /> <button :disabled="wnumtime>0"
		@click="getwnum">{{wnumtime>0?"倒计时:"+wnumtime:"获取验证码"}}</button>
	<br>
	<button @click="subfrom">提交</button>

</template>

<script setup>
	import axios from 'axios';
	import {
		ref
	} from 'vue';

	const tel = ref("")
	const wnum = ref("")
	const wnumtime = ref("")

	function getwnum() {
		axios.get("http://localhost:8080/getwnum/" + tel.value).then(function(res) {
			console.log(res.data)
			wnumtime.value = res.data
			upwnumtime()

		}).catch(function(res) {

		})
	}

	function upwnumtime() {
		if (wnumtime.value > 0) {
			wnumtime.value--
			window.setTimeout(upwnumtime, 1000)
		}

	}

	function subfrom() { //提交表单
		axios.post("http://localhost:8080/login", {
			"tel": tel.value,
			"wnum": wnum.value
		}).then(function(res) {
			if(res.data=="no"){
				alert("验证码错误")
			}else{
				alert("ok")
			}
			console.log(res.data)
		}).catch(function() {

		})
	}
</script>

<style>
</style>